/*
 * @(#)XMLMaker.java 0.5 08/12/04
 *
 * Copyright 2008 100town.com. All rights reserved.
 * Use is subject to license terms.
*/
package ImplSample;

import java.awt.event.KeyEvent;
import java.io.OutputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.collada._2005._11.colladaschema.Animation;
import org.collada._2005._11.colladaschema.FloatArray;
import org.collada.model.Action;
import org.collada.model.ActionType;
import org.collada.model.ControlKey;
import org.collada.model.Model;
import org.collada.anim.ModelControl;
import org.collada.model.ModifierKey;

public class XMLMaker {
	public static void outputModel(Model model, OutputStream out){
		try {
			JAXBContext context = JAXBContext.newInstance(Model.class);
			Marshaller marshaller = context.createMarshaller();
			marshaller.marshal(model, out);
		} catch (JAXBException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] argv){
		Model model = new Model();
		model.setURI("D:\test.dae");
		model.setId("id");
		model.setSid("sid");
		model.setName("name");
		//A Cube
		FloatArray geometry = new FloatArray();
		geometry.getValues().add(-50.0); geometry.getValues().add(50.0); geometry.getValues().add(50.0); geometry.getValues().add(50.0); geometry.getValues().add(50.0); geometry.getValues().add(50.0); geometry.getValues().add(-50.0); geometry.getValues().add(-50.0); geometry.getValues().add(50.0); geometry.getValues().add(50.0); geometry.getValues().add(-50.0); geometry.getValues().add(50.0); geometry.getValues().add(-50.0); geometry.getValues().add(50.0); geometry.getValues().add(-50.0); geometry.getValues().add(50.0); geometry.getValues().add(50.0); geometry.getValues().add(-50.0); geometry.getValues().add(-50.0); geometry.getValues().add(-50.0); geometry.getValues().add(-50.0); geometry.getValues().add(50.0); geometry.getValues().add(-50.0); geometry.getValues().add(-50.0);
		model.setGeometry(geometry);
		Animation animation = new Animation();
		animation.setName("animationID1");
		animation.setId("animationID1");
		model.getAnimations().add(animation);
		ModelControl control = new ModelControl();
		control.getAnimationIDs().add("animationID1");
		Action walkAction = new Action(){
		};
		walkAction.setActionID("Walk");
		walkAction.setActionType(ActionType.START);
		ControlKey controlKey = new ControlKey();
		controlKey.setKey(KeyEvent.VK_W);
		controlKey.getModifierKeys().add(ModifierKey.CTRL_DOWN_MASK);
		walkAction.getActionListenerClasses().add(ImplSample.action.ActionListenerAdapter.class);
		walkAction.setControlKey(controlKey);
		walkAction.setModelControl(control);
		model.getActions().add(walkAction);
		
		Action restAction = new Action(){
		};
		restAction.setActionID("Rest");
		restAction.setActionType(ActionType.STOP);
		ControlKey RcontrolKey = new ControlKey();
		RcontrolKey.setKey(KeyEvent.VK_R);
		RcontrolKey.getModifierKeys().add(ModifierKey.SHIFT_DOWN_MASK);
		restAction.getActionListenerClasses().add(ImplSample.action.ActionListenerAdapter.class);
		restAction.setControlKey(RcontrolKey);
		restAction.setModelControl(control);
		model.getActions().add(restAction);
		
		Action toggleAction = new Action(){
		};
		toggleAction.setActionID("Toggle");
		toggleAction.setActionType(ActionType.TOGGLE);
		ControlKey TcontrolKey = new ControlKey();
		TcontrolKey.setKey(KeyEvent.VK_T);
		TcontrolKey.getModifierKeys().add(ModifierKey.CTRL_DOWN_MASK);
		toggleAction.getActionListenerClasses().add(ImplSample.action.ActionListenerAdapter.class);
		toggleAction.setControlKey(TcontrolKey);
		toggleAction.setModelControl(control);
		model.getActions().add(toggleAction);
		
		Action oneStepAction = new Action(){
		};
		oneStepAction.setActionID("OneStep");
		oneStepAction.setActionType(ActionType.RUN_ONCE);
		ControlKey OcontrolKey = new ControlKey();
		OcontrolKey.setKey(KeyEvent.VK_O);
		OcontrolKey.getModifierKeys().add(ModifierKey.CTRL_DOWN_MASK);
		oneStepAction.getActionListenerClasses().add(ImplSample.action.ActionListenerAdapter.class);
		oneStepAction.setControlKey(OcontrolKey);
		oneStepAction.setModelControl(control);
		model.getActions().add(oneStepAction);
		
		Action FourStepAction = new Action(){
		};
		FourStepAction.setActionID("FourStep");
		FourStepAction.setActionType(ActionType.RUN_SEVERAL_TIMES);
		FourStepAction.setRunningTimes(4);
		ControlKey FcontrolKey = new ControlKey();
		FcontrolKey.setKey(KeyEvent.VK_F);
		FourStepAction.getActionListenerClasses().add(ImplSample.action.ActionListenerAdapter.class);
		FourStepAction.setControlKey(FcontrolKey);
		FourStepAction.setModelControl(control);
		model.getActions().add(FourStepAction);
		
		model.getControls().add(control);
		outputModel(model, System.out);
	}
}
